﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.MsAddrBook;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Ccit.OA.AddrBook
{
    public partial class addrbook_group_set : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                InitPage();
            }
        } 
        private void InitPage()
        {
            AddrBookBLL Bll = new AddrBookBLL();
            List<MsAddBookDetail> lstDetail = Bll.GetAddBookGroupMes();
            if(lstDetail.Count>0)
            {
                for (int i = 0; i < lstDetail.Count;i++ )
                {
                    MsAddBookDetail ms = lstDetail[i];
                    CreateTable(i,ms);
                }
                HtmlTableRow oRow1 = new HtmlTableRow();
                oRow1.Attributes["class"] = "row3";
                HtmlTableCell oCellDel1 = new HtmlTableCell();
                oCellDel1.ColSpan = 2;
                oCellDel1.InnerHtml = "&nbsp;";
                oRow1.Cells.Add(oCellDel1); 
                tbProduct.Rows.Add(oRow1); 
            }
            Bll = null;
        }

        private void CreateTable(int i, MsAddBookDetail ms)
        {
            string css = "";
            HtmlTableRow oRow = new HtmlTableRow();
            oRow.ID = "row_" + i.ToString();
            if (i % 2 == 0)
            {
                css = "row2";
            }
            else
            {
                css = "row3";
            }
            oRow.Attributes["class"] = css;

            HtmlTableCell oCellX = new HtmlTableCell();
            oCellX.Align = "center";
            //oCellX.Attributes["class"] = "listcellrow";
            oCellX.Attributes["width"] = "30%";
            oCellX.InnerHtml = "<a href=\"javascript:doEdIt(" + ms.ID + ",'" + i + "')\">";
            oCellX.InnerHtml += ""+ms.GroupName+"</a>";
            oRow.Cells.Add(oCellX);

            ////Operate 操作
            HtmlTableCell oCellDel = new HtmlTableCell();
            oCellDel.Align = "center";
           // oCellDel.Attributes["class"] = "listcellrow";
            oCellDel.Attributes["width"] = "10%";
            oCellDel.InnerHtml = "<a href=\"javascript:doRemoveRows('tbProduct'," + ms.ID + ",'" + oRow.ID + "')\">";
            oCellDel.InnerHtml += "删除</a>";
            oRow.Cells.Add(oCellDel); 

            tbProduct.Rows.Add(oRow); 
        }

        protected void lnbQuery_Click(object sender, EventArgs e)
        {
            InitPage();
        }
        #region Ajax Methods
        [global::System.Web.Services.WebMethod]
        public static string DoSaveMes(string strJson)
        {
            AddrBookBLL Bll = new AddrBookBLL();
            MsAddBookDetail ms = (MsAddBookDetail)JavaScriptConvert.DeserializeObject(strJson, typeof(MsAddBookDetail));
            string iNum = Bll.DoSaveGroupMes(ms); 
            Bll = null; 
            return iNum;
        }
        [global::System.Web.Services.WebMethod]
        public static string DoOperate(string sRecid)
        {
            AddrBookBLL Bll = new AddrBookBLL();
            string iNum = Bll.DaOperateGroup(sRecid);
            Bll = null;
            return iNum;
        }
        #endregion
    }
}
